/********************
Table 1. Summary Statistics by Uber Adoption Status
********************/
use "data\hslesshousehold_ubereitc2005_2019", clear

reghdfe selfemp max_total_credit2020 [pw = hhwt] if head_hsorless == 1 & hh_married == 0, absorb(st_yr cbsa_id num_ekids) vce(cluster stfips) 
gen esamp = e(sample) == 1

gen yr_uber = year(DateofEntry)
gen early = yr_uber<=2013
gen late = yr_uber>2013 & yr_uber<=2019
gen never = yr_uber == .

gen hh_single = hh_married == 0

cap file close sumstat
file open sumstat using "output\table_sumstat.tex", write replace
file write sumstat "\begin{tabular}{lcccc}" _n
file write sumstat "\toprule" _n
file write sumstat "\toprule" _n
file write sumstat "& Uber Before 2014 & Uber After 2014 & No Uber by 2019 & Within State Difference (2)-(1) \\" _n //& Pre-Difference & Post-Difference \\" _n
file write sumstat "& (1) & (2) & (3) & (4) \\" _n
file write sumstat "\midrule" _n
file write sumstat "\\" _n

local vars = "hh_nh_white hh_nh_black hh_nh_other hh_hisp hh_age_18_34 hh_age_35_54 hh_age_55_64 hh_age_over64 hh_married hh_single hh_lshs hh_hs anyemployed selfemp have_selfempinc  inctot2020 incwage2020 incbus002020"
local var_labs = `" "Non-Hispanic White" "Non-Hispanic Black" "Non-Hispanic Other" "Hispanic" "Head 18-34" "Head 35-54" "Head 55-64" "Head Over 64" "Married HH" "Single HH" "Head Less HS" "Head HS" "Any Employment" "Any Self-Employment" "Have Self-Employment Income" "HH Income (\\$2020)" "HH Wage Income (\\$2020)" "HH Self-Employment Income (\\$2020)" "'
local num: word count `vars'

forval i = 1/`num' {
	local var : word `i' of `vars'
	local varlab : word `i' of `var_labs'
	file write sumstat "`varlab'"
	reg `var' early late never [pw = hhwt] if esamp == 1, nocons vce(cluster stfips)
	file write sumstat " & " %7.2f (_b[early]) " & " %7.2f (_b[late]) " & " %7.2f (_b[never]) 
	
	reghdfe `var' late [pw = hhwt] if esamp == 1 & (early == 1 | late == 1), absorb(st_yr)  vce(cluster stfips)
	test late = 0
	local p = r(p)
	file write sumstat " & " %7.2f (_b[late])
	
	if `p'<.01 {
		file write sumstat "***"
	}
	if `p' >=.01 & `p'<.05 {
		file write sumstat "**"
	}
	if `p' >=.05 & `p'<.1 {
		file write sumstat "*"
	}
	file write sumstat "\\" _n
}

file write sumstat "\\" _n
file write sumstat "Observations"
foreach i in early late never {
		count if `i' ==1 & esamp == 1
		file write sumstat "&" %12.0gc (r(N))
}
file write sumstat "\\" _n
file write sumstat "\bottomrule" _n
file write sumstat "\bottomrule" _n
file write sumstat "\end{tabular}"
file close sumstat
